<template>
	<view>
		<view class="nav-custom" :style="[{height:CustomBar + 'px'}]">
			<view class="nav-bar" :style="style" :class="[bgImage!=''?'bg-img':'',bgColor]">
				<view class="action" @tap="BackPage" v-if="isBack">
					<text class="iconfont icon-zuo"></text>
					<slot name="backText"></slot>
				</view>
				<view class="content" :style="[{top:StatusBar + 'px'}]">
					<slot name="content"></slot>
				</view>
				<slot name="right"></slot>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				StatusBar: this.StatusBar,
				CustomBar: this.CustomBar
			};
		},
		name: 'nav-custom',
		computed: {
			style() {
				var StatusBar = this.StatusBar;
				var CustomBar = this.CustomBar;
				var bgImage = this.bgImage;
				var style = `height:${CustomBar}px;padding-top:${StatusBar}px;`;
				if (this.bgImage) {
					style = `${style}background-image:url(${bgImage});`;
				}
				return style
			}
		},
		props: {
			bgColor: {
				type: String,
				default: ''
			},
			isBack: {
				type: [Boolean, String],
				default: false
			},
			bgImage: {
				type: String,
				default: ''
			},
		},
		methods: {
			BackPage() {
				uni.navigateBack({
					delta: 1
				});
			}
		}
	}
</script>

<style lang="scss">
	.bg-gradual-red {
		background-image: var(--gradualRed);
		color: var(--white);
	}

	.bg-gradual-orange {
		background-image: var(--gradualOrange);
		color: var(--white);
	}

	.bg-gradual-green {
		background-image: var(--gradualGreen);
		color: var(--white);
	}

	.bg-gradual-purple {
		background-image: var(--gradualPurple);
		color: var(--white);
	}

	.bg-gradual-pink {
		background-image: var(--gradualPink);
		color: var(--white);
	}

	.bg-gradual-blue {
		background-image: var(--gradualBlue);
		color: var(--white);
	}

	.bg-img {
		background-size: cover;
		background-position: center;
		background-repeat: no-repeat;
	}

	.nav-custom {
		display: block;
		position: relative;

		.nav-bar {
			position: fixed;
			width: 100%;
			top: 0;
			z-index: 1024;
			-webkit-box-shadow: 0 1upx 6upx rgba(0, 0, 0, 0.1);
			box-shadow: 0 1upx 6upx rgba(0, 0, 0, 0.1);
			display: flex;
			align-items: center;
			
			.action {
				flex: 0 0 150upx;
				margin-left: 30upx;
				font-size: 30upx;
				color: #fff;
				display: flex;
				align-items: center;
				.iconfont{
					font-size: 40upx;
					color: #fff;
					margin-right: 10upx;
				}
			}

			.content {
				display: flex;
				flex: auto;
				justify-content: center;
				align-items: center;
				font-size: 32upx;
				color: #fff;
				position: absolute;
				left: 0;
				right: 0;
				bottom: 0;
				z-index: -1;
			}
		}
	}
</style>
